-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rewrite date & time formatting #3121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…elector. (#3092) Fixes #3078 Co-authored-by: Martin Dorey <[email protected]>
Fixes the names of configuration properties introduced after `2.10.0` to always use the normalized form. Fixes #3079
This commit: - Removes support for the outdated [Jansi 1.x](http://fusesource.github.io/jansi/) version in `Console` appender. - Rewrites `JAnsiTextRenderer`, use in the `%m{ansi}` and `%ex{ansi}` pattern converters to use our internal ANSI support instead of Jansi. Fixes #1736.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need DTF to print sub-day patterns (hours, minutes, seconds, etc.).
@ppkarwasz, what do you mean? If the pattern is, say, yyyy-MM-dd HH:mm:ss.SSS, we cache yyyy-MM-dd HH:mm: part and update it once per minute. I think this once-per-minute cost is negligible in a real-world setup.
Are you sure
DTFis garbage-free for these patterns? Can you add a test for it?
DTF is not garbage-free – no matter which method of DTF you use. Hence, neither our InstantPatternDynamicFormatter is garbage-free.
the
PatternSequences can actually be pre-computed, which would improve the time to generate the formatters.
Agreed, but I doubt if this additional complexity brings any practical benefit. Even my JMH tests run for 30 seconds, that is, they don't even encounter any sequencing operation.
Allow me to remind that my aim with this PR is not to implement the fastest instant formatter on top of DTF, but implement the simplest one with acceptable performance. FixedDF and FastDF were enough of a lesson for what happens with unsolicited complexity.
log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/DatePatternConverter.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java
Show resolved
Hide resolved
...-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/InstantFormatter.java
Show resolved
Hide resolved
...java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternDynamicFormatter.java
Show resolved
Hide resolved
.../src/main/java/org/apache/logging/log4j/layout/template/json/resolver/TimestampResolver.java
Show resolved
Hide resolved
...c/main/java/org/apache/logging/log4j/core/util/internal/instant/InstantPatternFormatter.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
In accordance with this
dev@discussion, these changesFixedDateTimeandFastDateTimeInstantFormattercontractInstantNumberFormatterfor epoch-related number-emitting formatting operationsInstantPatternNumbercontract for formatting based on a specified date & time patterInstantPatternThreadLocalCachedFormatterwhich wraps anyInstantPatternNumberand caches its values in aThreadLocalfor reusageInstantPatternDynamicFormatterthat uses Java'sDateTimeFormatterunder the hood such that the pattern is analyzed and parts that require a precision lower than or equal to minute are precomputed, cached, and updated per minute. That is,DateTimeFormatteris effectively only used for sub-minute parts, e.g.,ss.SSS.InstantPatternDynamicFormatterinternalsFor instance, given the pattern
yyyy-MM-dd'T'HH:mm:ss.SSSX, the generated formatter willMMis of month precision)yyyy-MM-dd'T'HH:mm:andX) and cache itss.SSS)GC implications
Since
DateTimeFormatteris not garbage-free, neither the newInstantPatternDynamicFormatteris.Performance implications
JDK: Azul Zulu
17.0.12OS: GNU/Linux
Date & time pattern:
yyyy-MM-dd'T'HH:mm:ss.SSSInstantPatternFormatterBenchmarkThis benchmark stresses instant formatting efficiency. 1000 instants are formatted per operation.
Interpretation: When used in isolation,
FixedDFyields a throughput of ~8x compared toInstantPF.InstantPatternFormatterImpactBenchmarkThis benchmark stresses instant formatting efficiency when combined with
PatternLayoutconfigured with the[%t] %p %-40.40c{1.} %notEmpty{%x }- %m%npattern. 1000LogEvents are formatted per operation.Using full log events (incl. exception, MDC & NDC):
Interpretation: When
LogEventcontains an exception, instant formatting efficiency becomes irrelevant.Using lite log events:
Interpretation: When
LogEventdoesn't contain an exception, MDC/NDC field, etc.,FixedDFyields a throughput of ~2x compared toInstantPF.Bug implications
Fixes #2943.